home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / network / daemons / bsd-ftpd.000 / bsd-ftpd / bsd.ftpd / err.c next >
Encoding:
C/C++ Source or Header  |  1995-09-09  |  4.4 KB  |  198 lines

  1. /*-
  2.  * Copyright (c) 1993
  3.  *    The Regents of the University of California.  All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice, this list of conditions and the following disclaimer in the
  12.  *    documentation and/or other materials provided with the distribution.
  13.  * 3. All advertising materials mentioning features or use of this software
  14.  *    must display the following acknowledgement:
  15.  *    This product includes software developed by the University of
  16.  *    California, Berkeley and its contributors.
  17.  * 4. Neither the name of the University nor the names of its contributors
  18.  *    may be used to endorse or promote products derived from this software
  19.  *    without specific prior written permission.
  20.  *
  21.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  22.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31.  * SUCH DAMAGE.
  32.  */
  33.  
  34. #if defined(LIBC_SCCS) && !defined(lint)
  35. /* from: static char sccsid[] = "@(#)err.c    8.1 (Berkeley) 6/4/93"; */
  36. static char *rcsid = "$Id: err.c,v 1.7 1993/11/06 00:55:23 cgd Exp $";
  37. #endif /* LIBC_SCCS and not lint */
  38.  
  39. #include <sys/cdefs.h>
  40. #include <errno.h>
  41. #include <stdio.h>
  42. #include <stdlib.h>
  43. #include <string.h>
  44.  
  45. #ifdef __STDC__
  46. #include <stdarg.h>
  47. #else
  48. #include <varargs.h>
  49. #endif
  50.  
  51. extern char *__progname;        /* Program name, from crt0. */
  52.  
  53. /* Prototypes. */
  54. void    err __P((int, const char *, ...));
  55. void    verr __P((int, const char *, va_list));
  56. void    errx __P((int, const char *, ...));
  57. void    verrx __P((int, const char *, va_list));
  58. void    warn __P((const char *, ...));
  59. void    vwarn __P((const char *, va_list));
  60. void    warnx __P((const char *, ...));
  61. void    vwarnx __P((const char *, va_list));
  62.  
  63. void
  64. #ifdef __STDC__
  65. err(int eval, const char *fmt, ...)
  66. #else
  67. err(eval, fmt, va_alist)
  68.     int eval;
  69.     const char *fmt;
  70.     va_dcl
  71. #endif
  72. {
  73.     va_list ap;
  74. #if __STDC__
  75.     va_start(ap, fmt);
  76. #else
  77.     va_start(ap);
  78. #endif
  79.     verr(eval, fmt, ap);
  80.     va_end(ap);
  81. }
  82.  
  83. void
  84. verr(eval, fmt, ap)
  85.     int eval;
  86.     const char *fmt;
  87.     va_list ap;
  88. {
  89.     int sverrno;
  90.  
  91.     sverrno = errno;
  92.     (void)fprintf(stderr, "%s: ", __progname);
  93.     if (fmt != NULL) {
  94.         (void)vfprintf(stderr, fmt, ap);
  95.         (void)fprintf(stderr, ": ");
  96.     }
  97.     (void)fprintf(stderr, "%s\n", strerror(sverrno));
  98.     exit(eval);
  99. }
  100.  
  101. void
  102. #if __STDC__
  103. errx(int eval, const char *fmt, ...)
  104. #else
  105. errx(eval, fmt, va_alist)
  106.     int eval;
  107.     const char *fmt;
  108.     va_dcl
  109. #endif
  110. {
  111.     va_list ap;
  112. #if __STDC__
  113.     va_start(ap, fmt);
  114. #else
  115.     va_start(ap);
  116. #endif
  117.     verrx(eval, fmt, ap);
  118.     va_end(ap);
  119. }
  120.  
  121. void
  122. verrx(eval, fmt, ap)
  123.     int eval;
  124.     const char *fmt;
  125.     va_list ap;
  126. {
  127.     (void)fprintf(stderr, "%s: ", __progname);
  128.     if (fmt != NULL)
  129.         (void)vfprintf(stderr, fmt, ap);
  130.     (void)fprintf(stderr, "\n");
  131.     exit(eval);
  132. }
  133.  
  134. void
  135. #if __STDC__
  136. warn(const char *fmt, ...)
  137. #else
  138. warn(fmt, va_alist)
  139.     const char *fmt;
  140.     va_dcl
  141. #endif
  142. {
  143.     va_list ap;
  144. #if __STDC__
  145.     va_start(ap, fmt);
  146. #else
  147.     va_start(ap);
  148. #endif
  149.     vwarn(fmt, ap);
  150.     va_end(ap);
  151. }
  152.  
  153. void
  154. vwarn(fmt, ap)
  155.     const char *fmt;
  156.     va_list ap;
  157. {
  158.     int sverrno;
  159.  
  160.     sverrno = errno;
  161.     (void)fprintf(stderr, "%s: ", __progname);
  162.     if (fmt != NULL) {
  163.         (void)vfprintf(stderr, fmt, ap);
  164.         (void)fprintf(stderr, ": ");
  165.     }
  166.     (void)fprintf(stderr, "%s\n", strerror(sverrno));
  167. }
  168.  
  169. void
  170. #ifdef __STDC__
  171. warnx(const char *fmt, ...)
  172. #else
  173. warnx(fmt, va_alist)
  174.     const char *fmt;
  175.     va_dcl
  176. #endif
  177. {
  178.     va_list ap;
  179. #ifdef __STDC__
  180.     va_start(ap, fmt);
  181. #else
  182.     va_start(ap);
  183. #endif
  184.     vwarnx(fmt, ap);
  185.     va_end(ap);
  186. }
  187.  
  188. void
  189. vwarnx(fmt, ap)
  190.     const char *fmt;
  191.     va_list ap;
  192. {
  193.     (void)fprintf(stderr, "%s: ", __progname);
  194.     if (fmt != NULL)
  195.         (void)vfprintf(stderr, fmt, ap);
  196.     (void)fprintf(stderr, "\n");
  197. }
  198.